{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b793093e-5425-49c3-bb26-cce25cd8e738",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/reorder-list\n",
    "\n",
    "\n",
    "Runtime: 28 ms, faster than 99.23% of C++ online submissions for Reorder List.\n",
    "Memory Usage: 20.2 MB, less than 5.05% of C++ online submissions for Reorder List.\n",
    "\n",
    "\n",
    "```cpp\n",
    "/**\n",
    " * Definition for singly-linked list.\n",
    " * struct ListNode {\n",
    " *     int val;\n",
    " *     ListNode *next;\n",
    " *     ListNode() : val(0), next(nullptr) {}\n",
    " *     ListNode(int x) : val(x), next(nullptr) {}\n",
    " *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n",
    " * };\n",
    " */\n",
    "class Solution {\n",
    "public:\n",
    "    void reorderList(ListNode* head) {\n",
    "      //7:20\n",
    "      vector<ListNode*> l;\n",
    "      auto node = head;\n",
    "      while (node != nullptr) {\n",
    "        l.push_back(node);\n",
    "        node = node->next;\n",
    "      }\n",
    "\n",
    "      vector<ListNode*> new_l;\n",
    "      int length = l.size();\n",
    "      for(int i=0; i<l.size(); i++) {\n",
    "        if (i > length-i-1) {\n",
    "          break;\n",
    "        } else if (i == length-i-1) {\n",
    "          new_l.push_back(l[i]);\n",
    "          break;\n",
    "        }\n",
    "        new_l.push_back(l[i]);\n",
    "        new_l.push_back(l[length-i-1]);\n",
    "      }\n",
    "\n",
    "      for(int i=0; i<length; i++) {\n",
    "        if (i == length-1) {\n",
    "          new_l[i]->next = nullptr;\n",
    "        } else {\n",
    "          new_l[i]->next = new_l[i+1];\n",
    "        }\n",
    "      }\n",
    "\n",
    "      return;\n",
    "      //7:23\n",
    "    }\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9c2b7c3b-2819-4b65-9d01-ef9088bc660a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "name": ""
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
